package com.china08.yxyapi.api.manage.edu.office;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.repository.mg.YxyNoticeInnerRepository;
import com.china08.yxyapi.repository.mg.YxyNoticeOutterRepository;

@CrossOrigin
@RestController
public class InnerAndOuterNoticeOnReadCountController extends YxyApiBaseController {

    @Autowired
    YxyNoticeInnerRepository yxyNoticeInnerRepository;

    @Autowired
    YxyNoticeOutterRepository yxyNoticeOutterRepository;

    @RequestMapping(value = "/api_yw/manage/edu/office/notice/noReadCount", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public RespModel precess(HttpServletRequest request, HttpServletResponse response) {

        String schoolId = getProfile(request, response).getSchoolId();
        String userId = getProfile(request, response).getId();

        Integer count1 = yxyNoticeInnerRepository.SchoolIdAndReceiverUserIdAndReceiverIsDeleteAndReceiverIsRead(schoolId, userId, 0, 0);
        Integer count2 = yxyNoticeOutterRepository.countByReceiveSchoolSchoolIdAndReceiveSchoolIsReadAndReceiveSchoolIsDelete(schoolId, 0, 0);

        RespModel respModel = new RespModel();
        respModel.count = count1 + count2;
        return respModel;
    }

    protected static class RespModel extends YxyApiRespModel {
        public int count;
    }
}
